import { parseTimeDot } from "@/utils/utils.js";
import { getMessage } from "@/static/js/message.js";
export default {
  data() {
    return {
      parseTimeDot,
      list: [],
      isLoading: false,
      page: 1,
      noMore: "noMore",
    };
  },

  onPullDownRefresh() {
    this.isLoading = true;
    this.list = [];
    this.page = 1;
    this.noMore = "loadmore";
    this.getList();
  },
  onReachBottom() {
    if (this.noMore == "noMore") return;
    this.page++;
    this.getList();
  },
  methods: {
    // 获取系统通知
    async getList() {
      this.noMore = "loading";
      const res = await getMessage({
        type: 3,
        page: this.page,
        pagesize: 10,
      });
      this.isLoading = false;
      if (res.code == 1) {
        if (res.data.length == 0 || res.data.length < 10) {
          this.noMore = "noMore";
        } else {
          this.noMore = "loadmore";
        }
        uni.stopPullDownRefresh();
        let list = res.data;
        list.forEach((e) => {
          e.createtime = parseTimeDot(e.createtime, "{m}-{d}");
          e.info = e.info.replace(/<[^>]*>/g, "");
        });
        this.list.push(...list);
      }
    },

    go(item) {
      let url = "";
      if (item.url.length > 1) return;
      if (item.url == 1) {
        url = "/pages/my/vip/index";
      } else if (item.url == 2) {
        url = "/pointsMall/pointsDetail/index";
      } else if (item.url == 3) {
        url = "/quiz/askInfo/index?id=" + item.quiz_id;
      } else if (item.url == 5) {
        url = "/pages/my/coupon/index";
      } else if (item.quiz_id != 0) {
        url = "/quiz/myAsk/index";
      }
      uni.navigateTo({ url });
    },
  },
  onLoad(e) {
    this.isLoading = true;
    this.getList();
  },
};